package com.wu.web;

import com.wu.bean.User;
import com.wu.service.UserService;
import com.wu.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 修改用户信息
 */
@WebServlet("/UpdateUser")
public class UpdateUserServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int userid=Integer.parseInt(req.getSession().getAttribute("userid").toString());
        String name=req.getParameter("name");
        int sex=Integer.parseInt(req.getParameter("sex"));
        String email=req.getParameter("email");
        String address=req.getParameter("address");
        String occupation=req.getParameter("occupation");
        String telephone=req.getParameter("telephone");
        UserService userService=new UserServiceImpl();
        int ok = userService.UpdateUser(new User(userid, null, name, null, sex, email, address, occupation, telephone));
        if(ok>0)
            resp.getWriter().print("ok");
        else
            resp.getWriter().print("no");

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
